/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.volokh.danylo.layoutmanager;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.app.Context;

public class CustomComponent extends Text implements Component.DrawTask{
    private Paint mPaintForCircle;
    private Paint mPaintForCross;

    private int mRadius;

    private int mXOrigin;
    private int mYOrigin;

    public CustomComponent(Context context) {
        super(context);
        mRadius = 1176;
        mXOrigin = -200;
        mYOrigin = 0;
        init();
        addDrawTask(this::onDraw);
    }


    public CustomComponent(Context context, AttrSet attrSet) {
        super(context, attrSet);
        mRadius = 1176;
        mXOrigin = -200;
        mYOrigin = 0;
        init();
        addDrawTask(this::onDraw);
    }

    private void init(){
        mPaintForCircle = new Paint();
        mPaintForCircle.setColor(Color.BLACK);
        mPaintForCircle.setAlpha(0.4f /*This is not percents*/);

        mPaintForCross = new Paint();
        mPaintForCross.setColor(Color.BLACK);
        mPaintForCross.setStrokeWidth(5);
        invalidate();
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
        canvas.drawCircle(mXOrigin, mYOrigin, mRadius, mPaintForCircle);
        canvas.drawLine(mXOrigin, mYOrigin, 3000, mYOrigin, mPaintForCross);
        canvas.drawLine(mXOrigin, mYOrigin, -3000, mYOrigin, mPaintForCross);
        canvas.drawLine(mXOrigin, mYOrigin, mXOrigin, 3000, mPaintForCross);
        canvas.drawLine(mXOrigin, mYOrigin, mXOrigin, -3000, mPaintForCross);
    }
}
